package figure8.events;

import java.util.LinkedList;
import java.util.List;

import figure8.Network.Client;
import figure8.Network.Message;

public class NetworkEventSource {
	protected List<NetworkEventListener> listeners;
	
	public NetworkEventSource() {
		this.listeners = new LinkedList<NetworkEventListener>();
	}
	
	public void addNetworkEventListener(NetworkEventListener listener) {
		this.listeners.add(listener);
	}

	public void removeNetworkEventListener(NetworkEventListener listener) {
		this.listeners.remove(listener);
	}

	protected void fireNetworkDisconnectEvent() {
		for (NetworkEventListener listener : this.listeners) {
			listener.networkDisconnect(new NetworkDisconnectEvent(this));
		}
	}

	protected void fireNetworkMessageEvent(Message message, Client client) {
		for (NetworkEventListener listener : this.listeners) {
			listener.networkMessage(new NetworkMessageEvent(this, message, client));
		}
	}
}
